package com.njworkorder.Config;

import com.qingstor.sdk.config.EnvContext;
import com.qingstor.sdk.service.Bucket;
import com.qingstor.sdk.service.QingStor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class QyOssConfig {

    @Value("${qy.oss.access_key_id}")
    private String accessKeyId;
    @Value("${qy.oss.secret_access_key}")
    private String accessKeySecret;
    @Value("${qy.oss.bucket_name}")
    private String bucketName;
    @Value("${qy.oss.zone_name}")
    private String zoneName;

    @Bean(name = "qingStor")
    public QingStor qingStor()
    {
        EnvContext env = new EnvContext(accessKeyId, accessKeySecret);
        return new QingStor(env);
    }

    @Bean(name = "qyBucket")
    public Bucket getBucket(){
       return qingStor().getBucket(bucketName,zoneName);
    }
}
